package com.example.jpatest.exception;

import com.example.jpatest.exception.competitionException.CompetitionExistException;
import com.example.jpatest.exception.competitionException.CompetitionNotExistException;
import com.example.jpatest.exception.enterException.HasEnterException;
import com.example.jpatest.exception.enterException.NoEnterException;
import com.example.jpatest.exception.teacherException.TeacherExistException;
import com.example.jpatest.exception.teacherException.TeacherNotExistException;
import com.example.jpatest.exception.teamException.HasInTeamException;
import com.example.jpatest.exception.teamException.NotInTeamException;
import com.example.jpatest.exception.studentException.StudentExistException;
import com.example.jpatest.exception.studentException.StudentNotExistException;
import com.example.jpatest.exception.teamException.TeamExistException;
import com.example.jpatest.exception.teamException.TeamNotExistException;
import com.example.jpatest.unit.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 异常处理
 * @author czx
 */

@ControllerAdvice
public class ResultExceptionHandler {
    @ExceptionHandler(StudentExistException.class)
    @ResponseBody
    public Result studentExistException(StudentExistException studentExistException){
        return Result.msg("学生已存在");
    }

    @ExceptionHandler(StudentNotExistException.class)
    @ResponseBody
    public Result studentNotExistException(StudentNotExistException studentNotExistException){
        return Result.msg("学生不存在");
    }

    @ExceptionHandler(CompetitionNotExistException.class)
    @ResponseBody
    public Result competitionNotExistException(CompetitionNotExistException competitionNotExistException){
        return Result.msg("竞赛不存在");
    }

    @ExceptionHandler(CompetitionExistException.class)
    @ResponseBody
    public Result competitionNotExistException(CompetitionExistException competitionNotExistException){
        return Result.msg("竞赛已存在");
    }

    @ExceptionHandler(TeamExistException.class)
    @ResponseBody
    public Result teamExistException(TeamExistException teamExistException){
        return Result.msg("队伍已存在");
    }

    @ExceptionHandler(TeamNotExistException.class)
    @ResponseBody
    public Result teamNotExistException(TeamNotExistException teamExistException){
        return Result.msg("队伍未存在");
    }

    @ExceptionHandler(HasInTeamException.class)
    @ResponseBody
    public Result hasInTeamException(HasInTeamException hasInTeamException){
        return Result.msg("已加入该队伍");
    }

    @ExceptionHandler(NotInTeamException.class)
    @ResponseBody
    public Result notInTeamException(NotInTeamException notInTeamException){
        return Result.msg("未加入该队伍");
    }

    @ExceptionHandler(TeacherExistException.class)
    @ResponseBody
    public Result teacherExistException(TeacherExistException teacherExistException){
        return Result.msg("老师已存在");
    }

    @ExceptionHandler(TeacherNotExistException.class)
    @ResponseBody
    public Result teacherNotExistException(TeacherNotExistException teacherNotExistException){
        return Result.msg("老师不存在");
    }

    @ExceptionHandler(HasEnterException.class)
    @ResponseBody
    public Result hasEnterException(HasEnterException hasEnterException){
        return Result.msg("已报名");
    }

    @ExceptionHandler(NoEnterException.class)
    @ResponseBody
    public Result noEnterException(NoEnterException noEnterException){
        return Result.msg("未报名");
    }
}
